package com.sleepless.my.controller;

import com.sleepless.my.config.CustomUserDetails;
import com.sleepless.my.io.RestBean;
import com.sleepless.my.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping(value = "/api",produces = "application/json;charset=UTF-8")
@Slf4j
public class Debug {
//    private final JwtUtil jwtUtils;
//
//    public Debug(JwtUtil jwtUtils) {
//        this.jwtUtils = jwtUtils;
//    }

    @GetMapping("/now")
    public Object Now() {
        long timestamp = new Date().getTime();
        return RestBean.success("当前时间: "+timestamp);
    }

    @GetMapping("/ping")
    public Object Ping(){
        return RestBean.success("pong");
    }

    @GetMapping("/jwt")
    public Object getJwt(){
        String token=JwtUtil.createJWT(JwtUtil.createClaims("test"));
        return RestBean.success(token);
    }

    @GetMapping("/detail")
    public Object detail(@AuthenticationPrincipal CustomUserDetails customUserDetails){
        return RestBean.success(customUserDetails);
    }
}
